1380G - Circular Dungeon - CodeForces Solution


greedy math probabilities *2600

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define int ll
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vpi;
typedef pair<pi, ll> pii;
typedef set<ll> si;
typedef long double ld;
#define f first
#define s second
#define mp make_pair
#define FOR(i, s, e) for (int i = s; i <= int(e); ++i)
#define DEC(i, s, e) for (int i = s; i >= int(e); --i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i, x) for (auto i : x)
#define mem(x, i) memset(x, i, sizeof x)
#define fast ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define maxn 500010
#define INF (ll)1e9
#define MOD 998244353
typedef pair<vi, int> pvi;
typedef pair<int, pi> ipi;
typedef vector<pii> vpii;
#define DEBUG 0
typedef pair <pi,pi> pipi;
typedef vector <pipi> vpipi;
typedef pair <string, int> psi;


int N,A[maxn],ss[maxn];
int qexp(int a,int b){
	int ans = 1;
	while (b){
		if (b&1) (ans *= a) %= MOD;
		(a *= a) %= MOD;
		b >>= 1;
	}
	return ans;
}
void solve(){
	cin >> N;
	FOR(i,1,N) cin >> A[i];
	sort(A+1,A+N+1,greater <int> ());
	FOR(i,1,N) ss[i] = (ss[i-1] + A[i])%MOD;
	
	int invN = qexp(N,MOD-2);
	FOR(k,1,N){
		int res = 0;
		for (int i=1,j=0;i<=N; i+=k,j++){
			(res += (j*(ss[min(N,i+k-1)] - ss[i-1]))%MOD)%=MOD;
		}
		res = (res + MOD) % MOD;
		cout << (res*invN)%MOD << ' ';
	}
}

int32_t main() {
	fast;
	
	solve();
	//~ cin >> TC;
	//~ while (TC--) solve();
	
}


Comments

Submit
0 Comments
More Questions

7A - Kalevitch and Chess
912B - New Year's Eve
1537C - Challenging Cliffs
879B - Table Tennis
1674E - Breaking the Wall
1282A - Temporarily unavailable
1366C - Palindromic Paths
336A - Vasily the Bear and Triangle
926A - 2-3-numbers
276D - Little Girl and Maximum XOR
1253C - Sweets Eating
1047A - Little C Loves 3 I
758D - Ability To Convert
733A - Grasshopper And the String
216A - Tiling with Hexagons
1351B - Square
1225A - Forgetting Things
1717A - Madoka and Strange Thoughts
1717B - Madoka and Underground Competitions
61B - Hard Work
959B - Mahmoud and Ehab and the message
802G - Fake News (easy)
1717C - Madoka and Formal Statement
420A - Start Up
1031A - Golden Plate
1559C - Mocha and Hiking
427B - Prison Transfer
330A - Cakeminator
426A - Sereja and Mugs
363A - Soroban